export default function useRecorder(
  stopCallback: (res: WechatMiniprogram.OnStopCallbackResult) => void,
) {
  const recorderManager = wx.getRecorderManager()

  recorderManager.onError((res) => {
    console.error('🚀 -- recorderManager.onError -- res.errMsg', res.errMsg)
  })

  recorderManager.onStop((res) => {
    stopCallback(res)
  })

  return {
    recorderStart() {
      // const options: RecorderManagerStartOption = {
      //   duration: 10000,
      //   sampleRate: 44100,
      //   numberOfChannels: 1,
      //   encodeBitRate: 192000,
      //   format: 'aac',
      //   frameSize: 50,
      // }

      recorderManager.start({
        duration: 10000,
        // sampleRate: 44100,
        // numberOfChannels: 1,
        // encodeBitRate: 192000,
        format: 'mp3',
        // frameSize: 50,
      })
    },
    recorderStop() {
      recorderManager.stop()
    },
  }
}
